<template>
	<view class="evalute-page">
		<view class="evalute-item flex-y-center">
			<view class="label">
				敏感区域：
			</view>
			<view class="input">
				<uv-input border="none" v-model="FormData.sensitiveAreas" placeholder="请输入用户的敏感区域"></uv-input>
			</view>
		</view>
		<view class="evalute-tboyd">
			<view class="label">
				服务总结：
			</view>
			<view class="evalute-remark">
				<uv-textarea border="none" v-model="FormData.serviceSummary" customStyle="background-color:#f1f1f1"
					placeholder="服务满足你的期待吗？说说你的使用心得"></uv-textarea>
			</view>

			<view class="label" style="margin-bottom: 20rpx;">
				服务客户图片：
			</view>
			<view class="up-image">
				<uv-upload :fileList="fileList1" name="1" multiple :maxCount="10" :previewFullImage="true"
					@afterRead="afterRead" @delete="deletePic"></uv-upload>
			</view>
		</view>

		<uv-button color="#5ebcbc" :customStyle="{'border-radius':'10rpx',width:'690rpx'}"
			@click="submit">发布</uv-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				evalutevalue: 5,
				fileList1: [],
				remark: '',
				FormData: {
					ossIds: [],
					strengthEvaluate: 5,
					temperatureEvaluate: 5,
					evaluateRemark: null,
					appUserId: null, //用户id
					userId: null, //技师id
					orderId: null, //訂單id
					healthType: null,
					sensitiveAreas: null,
					serviceSummary: null,

				},
			}
		},
		onLoad(e) {
			this.FormData.orderId = e.orderId
			this.FormData.userId = e.userId
			this.FormData.appUserId = e.appUserId
		},
		methods: {
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						// status: 'uploading',
						// message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					console.log(lists[i].url)
					const {
						data,
						code
					} = await this.muajax.UploadFiles({}, {
						filePath: lists[i].url,
						name: 'file',
					})
					this.FormData.ossIds.push(data.ossId)
					// let item = this[`fileList${event.name}`][fileListLen]
					// this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
					// 	status: 'success',
					// 	message: '',
					// }))
					// fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
			async submit() {
				const {
					data,
					code
				} = await this.muajax.accountantEvaluate({
					...this.FormData,
					ossIds:this.FormData.ossIds.toString()
				})
				if (code == 200) {
					uni.showToast({
						icon: 'success',
						title: '评论成功'
					})
					uni.navigateBack()
				}

				// userEvaluate
				console.log('提交评论')
			}

		}
	}
</script>

<style scoped lang="less">
	.evalute-page {
		padding: 30rpx;
		box-sizing: border-box;
	}

	.evalute-header {
		background-color: #ffffff;
		border-radius: 10rpx;
		padding: 30rpx;
		box-sizing: border-box;

		.evalute-pic {
			width: 54rpx;
			height: 54rpx;
			margin-right: 30rpx;
		}

		.header-cont {
			.evalute-item {
				margin: 13rpx 0px;
				display: flex;
				align-items: center;
			}

			text {
				font-size: 30rpx;
				font-weight: bold;
				font-stretch: normal;
				letter-spacing: 0rpx;
				color: #333333;
			}
		}

	}

	.evalute-tboyd {
		margin-top: 20rpx;
		background-color: #ffffff;
		border-radius: 10rpx;
		padding: 30rpx;
		box-sizing: border-box;
		margin-bottom: 68rpx;

		.evalute-remark {
			margin-bottom: 20rpx;
			padding: 20rpx 0px;
			box-sizing: border-box;
			// background-color: #f1f1f1;
		}
	}

	.evalute-item {
		margin-top: 20rpx;
		background-color: #ffffff;
		border-radius: 10rpx;
		padding: 30rpx;
	}
</style>